home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11883 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  80 lines

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q: how to create an Object without creating the whole object
  5. Date: Sat, 16 Mar 1996 21:15:34 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4ifb0a$5q0@news.halcyon.com>
  8. References: <31454EC9.167E@imacsg2.epfl.ch> <4i9eqo$dtu@uuneo.neosoft.com>
  9. NNTP-Posting-Host: blv-pm3-ip13.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Wmatthew@lan-aces.com (W. Matthews) wrote:
  13.  
  14. >In article <31454EC9.167E@imacsg2.epfl.ch>, Niels Hilbrink <niels@imacsg2.epfl.ch> says:
  15. >>
  16. >>Hi,
  17. >>
  18. >>Oke the problem is this (maybe it's in a FAQ but couldn't find the faq
  19. >>so ...):
  20. >>
  21. >>Say you've got a class A which is composed of say 10 other class
  22. >>(inheritance multiple and single whatever). But if I create an object
  23. >>with new this class 'explodes' (all the member functions are created of
  24. >>all the parentclasses) so you want the initialize only those parent
  25. >>class you need say only class B.
  26. >>
  27. >>How do you do that ?
  28. >>
  29. >>something like:
  30. >>        
  31. >>        Aobj = (A*) new A::B()
  32. >>
  33. >>But this doen't work, can anybody tell me what will ?
  34. >>
  35. >>oh yeah this works of course :
  36. >>        Bobj = new B;
  37. >>
  38. >>        Aobj = (A*) Bobj;
  39. >>
  40. >>but I don't want that, I don't want first to  have to create a B object
  41. >>and "attach" it to the A object
  42. >>
  43. >>Gr.
  44. >>Niels
  45. >>
  46. >>-- 
  47. >>
  48. >>   The most overlooked advantage to owning a computer is 
  49. >>   that if they foul up there's no law against wacking   
  50. >>   them around a little.                                 
  51. >>
  52. >>------------------------------------------------------------
  53. >>Koen D'Hondt                                  Niels Hilbrink
  54. >>koen@dutlhs1.lr.tudelft.nl      niels@dutlcc3.lr.tudelft.nl
  55. >>
  56. >>**** Ripley Software Development ****
  57. >>(finger niels@dutlcc3.lr.tudelft.nl for more information.)
  58. >>------------------------------------------------------------
  59. >Have you tried using a generic base class?  Then, in class 'A'
  60. >call the base with the appropriate class conversions to get 'B'.
  61. ><Don't mind me, I may turn out to be rambling on this one.>
  62. >______________________________________________
  63. >|Wyatt Matthews:       Tech Support Department |
  64. >|WMATTHEW@LAN-ACES.COM        -Internet-       |
  65. >|WMATTHEW.MHS@LAN-ACES          -MHS-          |
  66. >|LAN-ACES Tech Support      (713)890-9786      |
  67. >|LAN-ACES BBS               (713)890-9790      |
  68. >|LAN-ACES Fax               (713)890-9731      |
  69. >|LAN-ACES Sales             (713)890-9787      |
  70. >______________________________________________
  71.  
  72. Sorry, it's all or nuthin.  How's a compiler supposed to know  what
  73. methods you'll want to use?  
  74.  
  75. Creating a B, playing on it, then 'attaching' it to A (i.e, tell A to
  76. use the B *) is all you're left with.
  77.  
  78.                     --Norm 
  79.  
  80.